package cate.game.role.world.invite.msg;

import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBWorld;
import cate.game.role.Role;
import cate.game.role.world.invite.RoleInvite;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcException;

@ClientMsg(title = "邀请任务奖励领取 の 请求")
public class InviteTaskRewardGetReq implements MsgInput {

    @NoteField(value = "任务类型", detail = "创建任务=1, 登录任务=2, 拆红包=3, 30级任务=4, 60级任务=5, 首充任务=6")
    public int taskType;

    @NoteField(value = "tid")
    public int tid;

    @NoteField("邀请人的uid")
    public String loginInviterId;

    @Override
    public int getOperation() {
        return GDOperation.INVITE;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        h(game, cc.getRole());
    }

    public void h(GameBody game, Role role) {
        perform(game, role, () -> {
            final RoleInvite ri = role.getBase().invite;
            switch (taskType) {
                case 1:
                    ri.createTask.tryGetReward(role, tid);
                    InviteTaskUpdateResp.build(ri.createTask).sendNow(role);
                    break;
                case 2:
                    ri.loginTask.tryGetReward(role, tid);
                    InviteTaskUpdateResp.build(ri.loginTask).sendNow(role);
                    break;
                case 3:
                    ri.redPkgTask.tryGetReward(role, loginInviterId);
                    InviteTaskUpdateResp.build(ri.redPkgTask).sendNow(role);
                    break;
                case 4:
                    ri.lvUpTask.tryGetReward(role,30, tid);
                    InviteTaskUpdateResp.build(ri.lvUpTask).sendNow(role);
                    break;
                case 5:
                    ri.lvUpTask.tryGetReward(role,60, tid);
                    InviteTaskUpdateResp.build(ri.lvUpTask).sendNow(role);
                    break;
                case 6:
                    throw new EcException("这不是主动领取的，是系统直接发放的").s();
                default:
                    throw new EcException("不支持的taskType="+taskType).s();
            }
        });
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBWorld.INVITE_TASK_REWARD_GET_REQ;
    }
}
